/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DragBarPanelPackage;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JLabel;

/**
 *
 * @author Evan
 */
public class DragBarButton extends JButton
{

  public static final Color DEFAULT_COLOR = new Color(220, 220, 220);
  public static final Color HORIZONTAL_LOCK_COLOR = new Color(220, 220, 255);
  private boolean isExpanded = false;
  // buttons that are Horizontally locked cannot be moved horizontally
  private boolean isHorizontallyLocked = true;
  private boolean isPressed = false;
  private Point oldLocation = new Point(0, 0);
  private Dimension oldSize = new Dimension(50, 50);
  // The value to be displayed on the button (or label)
  private double value = 0;
  // The previous value displayed
  private double previousValue = 0;
  // the label
  private JLabel theLabel;
  // label font
  private Font labelFont = new Font("Tahoma", 1, 14);
  // test old size
  private static Dimension defaultSize;
  private boolean usingUserDefinedLabel = false;
  private String userDefinedLabelText = null;

  public DragBarButton()
  {
    super();
    theLabel = new JLabel("0.0");
    theLabel.setFont(labelFont);
  }

  public DragBarButton(Action a)
  {
    super(a);
    theLabel = new JLabel("0.0");
    theLabel.setFont(labelFont);
  }

  public DragBarButton(String s)
  {
    super(s);
    theLabel = new JLabel("0.0");
    theLabel.setFont(labelFont);
  }

  public Point getOldLocation()
  {
    return oldLocation;
  }

  public Dimension getOldSize()
  {
    return oldSize;
  }

  public static Dimension getDefaultSize()
  {
    return defaultSize;
  }

  public boolean isExpanded()
  {
    return isExpanded;
  }

  public boolean isHorizontallyLocked()
  {
    return isHorizontallyLocked;
  }

  public boolean isPressed()
  {
    return isPressed;
  }

  public double getValue()
  {
    return value;
  }

  public double getPreviousValue()
  {
    return previousValue;
  }

  public double getValueDifference()
  {
    return value - previousValue;
  }

  public JLabel getTheLabel()
  {
    return theLabel;
  }

  public void setOldLocation(Point point)
  {
    oldLocation = point;
  }

  public void setOldSize(Dimension size)
  {
    oldSize = size;
  }

  public void setIsExpanded(boolean bool)
  {
    isExpanded = bool;
  }

  public void setIsPressed(boolean bool)
  {
    isPressed = bool;
  }

  public void setValue(double newValue)
  {
    previousValue = value;
    value = newValue;
  }

  public void setHorizontallyLocked(boolean bool)
  {
    isHorizontallyLocked = bool;
  }

  public static void setDefaultSize(Dimension newDefault)
  {
    defaultSize = newDefault;
  }

  public boolean usingUserDefinedLabel()
  {
    return usingUserDefinedLabel;
  }

  public String getUserDefinedLabelText()
  {
    return userDefinedLabelText;
  }

  public void setUserDefinedLabel(String newLabelText)
  {
    if (newLabelText == null)
    {
      usingUserDefinedLabel = false;
    }
    else
    {
      usingUserDefinedLabel = true;
      userDefinedLabelText = newLabelText;
    }
  }

  // clones this button
  public DragBarButton clone()
  {
    DragBarButton ret = new DragBarButton();

    ret.isExpanded = this.isExpanded;
    ret.isHorizontallyLocked = this.isHorizontallyLocked;
    ret.isPressed = this.isPressed;
    ret.value = this.value;
    ret.previousValue = this.previousValue;

    ret.oldLocation = (Point) this.oldLocation.clone();
    ret.oldSize = (Dimension) this.oldSize.clone();
    ret.defaultSize = (Dimension) this.defaultSize.clone();

    ret.theLabel.setText(this.theLabel.getText());
    ret.theLabel.setFont(this.labelFont);

    ret.setText(this.getText());
    ret.setName(this.getName());

    // this one is fishy... but should be OK b/c we won't be changing fonts too
    // often.  wish java had made fonts cloneable
    ret.labelFont = this.labelFont;

    return ret;
  }

  // copies input into this button
  public void copy(DragBarButton toBeCopied)
  {
    this.isExpanded = toBeCopied.isExpanded;
    this.isHorizontallyLocked = toBeCopied.isHorizontallyLocked;
    this.isPressed = toBeCopied.isPressed;
    this.value = toBeCopied.value;
    this.previousValue = toBeCopied.previousValue;

    this.oldLocation = (Point) toBeCopied.oldLocation.clone();
    this.oldSize = (Dimension) toBeCopied.oldSize.clone();
    this.defaultSize = (Dimension) toBeCopied.defaultSize.clone();

    this.theLabel.setText(toBeCopied.theLabel.getText());
    this.theLabel.setFont(toBeCopied.labelFont);

    this.setText(toBeCopied.getText());
    this.setName(toBeCopied.getName());

    // this one is fishy... but should be OK b/c we won't be changing fonts too
    // often.  wish java had made fonts cloneable
    this.labelFont = toBeCopied.labelFont;
  }
}
